﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EBA.Contracts;

namespace EBA.Notifications
{
    /// <summary>
    /// 通知推送
    /// </summary>
    public static class NotificationProviderEx
    {
        /// <summary>
        /// 新增通知
        /// </summary>
        /// <param name="provider">通知数据提供者</param>
        /// <param name="recipient">接收者</param>
        /// <param name="title">主题</param>
        /// <param name="messageName">消息名称</param>
        /// <param name="messageData">完整消息内容</param>
        /// <returns>通知Id</returns>
        public static string Send(this INotificationProvider provider, string recipient, string title, string messageName, byte[] messageData)
        {
            Contract.Requires<ArgumentNullException>(provider != null, "provider");

            var notification = provider.Notifications.NewEntity();
            notification.Id = Guid.NewGuid().ToString("N");
        
            notification.Recipient = recipient;
            notification.Title = title;

            notification.MessageName = messageName;
            notification.MessageData = messageData;

            provider.Notifications.Add(notification);
            provider.SubmitChanges();

            return notification.Id;
        }
    }
}
